package com.gonsin.gview.model.form;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import com.gonsin.gview.model.GFormItemModel;
import com.gonsin.gview.model.data.GListDataModel;
import com.gonsin.i18n.logic.T;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@ApiModel("下拉选择框")
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class GSwitchBoxModel extends GFormItemModel {

    @ApiModelProperty("check_box表示复选框，还有check_box\\file\\radio\\rich_text\\text_input\\tree_check_box\\tree_selector")
    private final String itemType = "switch";

    @ApiModelProperty("是否必选")
    private boolean required;

    @ApiModelProperty("查询或者提交表单时，表示  ${keyName}=value")
    private String keyName;

    @ApiModelProperty("显示的名字")
    private String name;

    @ApiModelProperty("提示语")
    private String placeholder;

    @ApiModelProperty("判断条件显示，支持js语法，例如   showIf=\"type==1\"")
    private String showIf;

    @ApiModelProperty("根据情况禁用")
    private String disableIf;

    @ApiModelProperty("当单个表单项被修改时，触发对应的action事件")
    private String buttonId;

    @ApiModelProperty("数据获取相关")
    private GListDataModel listData;

    @Override
    public GFormItemModel tClone() {
        GSwitchBoxModel model = new GSwitchBoxModel();
        BeanUtil.copyProperties(this, model, CopyOptions.create().setIgnoreNullValue(true));
        if(name != null){
            model.setName(T.t(name));
        }
        if(placeholder != null){
            model.setPlaceholder(T.t(placeholder));
        }
        return model;
    }


}
